package com.topone.Aspect;

import com.topone.dataObject.UserLoginHistory;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by Administrator on 2018/3/4,0004.
 */
@Aspect
@Component
public class UserLoginAspect {

      UserLoginHistory userLoginHistory=new UserLoginHistory();

    @Pointcut("execution(public * com.topone.controller.WechatController.userInfo(..))")
    public void loginLog(){}

    @After("loginLog()")
    public void after(JoinPoint joinPoint){
        ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        HttpServletRequest request = attributes.getRequest();
        userLoginHistory.setUserip(request.getRequestURI());
    }

}
